﻿using Mysqlx.Crud;

namespace AppData
{
    public class MovieItemData
    {
        public long movieId;
        public string title = "";
        public string iconUrl = "";
        public long watchTimes;
        public int episodeCount;
        public string type;
        public string desc;

        public MovieItemData(ShortMovie e)
        {
            if (e != null)
            {
                this.movieId = e.id;
                this.title = e.info.name;
                this.iconUrl = e.info.icon;
                this.watchTimes = e.info.watchTimes;
                this.episodeCount = e.episodeCount;
                this.type = e.info.sub_genre;
                this.desc = e.info.description;
            }
        }
    }

    public class TypeMovieItems
    {
        public List<MovieItemData> itemDatas;
    }

    public class MovieData
    {
        public MovieItemData info;
        public List<VideoData> videoDatas;
        public MovieData(ShortMovie shortMovie)
        {
            this.info = new MovieItemData(shortMovie);

            videoDatas = new List<VideoData>();
            for (int i = 0; i < shortMovie.episodes.Length; i++)
            {
                var videoData = shortMovie.episodes[i];
                videoDatas.Add(new VideoData(info.movieId,i+1, videoData.url, 
                    videoData.icon, videoData.title, videoData.desc, videoData.publishedDate
                    , videoData.approved,videoData.watchTimes));
            }
        }
    }

    public class VideoData
    {
        public long movieId;
        public int episodeId;
        public string url;
        public string icon;
        public string title;
        public string desc;
        public int publishedDate;
        public bool approved;
        public long watchTimes;

        public VideoData(long movieId, int episodeId, string url, string icon, 
            string title, string desc, int publishedDate, bool approved, long watchTimes)
        {
            this.movieId = movieId;
            this.episodeId = episodeId;
            this.url = url;
            this.icon = icon;
            this.title = title;
            this.desc = desc;
            this.publishedDate = publishedDate;
            this.approved = approved;
            this.watchTimes = watchTimes;
        }

        public VideoData(videos table,string url,string icon)
        {
            this.movieId = table.movie_id;
            this.episodeId = table.episode_id;
            this.title = table.name;
            this.desc = table.description;
            this.publishedDate = table.publish_date;
            this.approved = table.approved > 0 ? true : false;
            this.watchTimes = table.watch_times;
            this.url = url;
            this.icon = icon;
        }

    }
}
